#include "ShieldBuff.h"
#include "StateBar.h"
#include "EffectFactory.h"
#include "EffectDefine.h"
#include "MainLayer.h"


ShieldBuff::ShieldBuff(void)
{
	_effect = NULL;
}


ShieldBuff::~ShieldBuff(void)
{
	CC_SAFE_RELEASE(_effect);
}

void ShieldBuff::onStart(StateBar* stateBar)
{
	PlayerPlane* plane = getPlane();
	plane->setIsProtected(true);

	Effect* eff = EffectFactory::sharedEffectFactory()->createEffect(SHIELD_EFFECT);
	eff->setPosition(plane->boundingBox().size.width/2, plane->boundingBox().size.height/2);
	plane->addChild(eff);
	setEffect(eff);
}


void ShieldBuff::onComplete()
{
	getPlane()->setIsProtected(false);
	getPlane()->removeChild(_effect);
}

bool ShieldBuff::init()
{
	if (!BaseBuff::init())
		return false;

	CCSprite* sprite = CCSprite::createWithSpriteFrameName("undying_icon.png");
	sprite->setAnchorPoint(ccp(0.5f, 0.5f));
	sprite->setPosition(ccp(getBlackMask()->boundingBox().getMidX(), getBlackMask()->boundingBox().getMidY()));
	addChild(sprite, 0);

	getBlackMask()->setScaleY(1.0f);

	return true;
}
